package iteratorPattern.demo;

import aggregate.Arts;
import aggregate.ISubject;
import aggregate.Science;
import iterator.IIterator;

/**
 * Created by DELL
 * Date: 2019/10/9.
 * Time: 15:23
 */
public class IteratorPatternEx {
    public static void main(String[] args) {
        System.out.println("***Iterator Pattern Demo***");
        ISubject sc_subject = new Science();
        ISubject ar_subject = new Arts();

        IIterator sc_iterator = sc_subject.createIterator();
        IIterator ar_iterator = ar_subject.createIterator();

        System.out.println("\nScienc subjects");
        print(sc_iterator);

        System.out.println("\nArts subjects");
        print(ar_iterator);

    }
    public static void print(IIterator iterator){
        while(!iterator.isDone()){
            System.out.println(iterator.next());
        }
    }

}
